package org.fhm.zdte.common.standard;

import org.fhm.zdte.common.annotation.MapperParameter;
import org.fhm.zdte.common.annotation.RequestBody;
import org.fhm.zdte.common.exception.ServletException;
import org.fhm.zdte.common.pojo.Servlet;

import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Map;

/**
 * The annotations that to tag method arguments of {@link Servlet} are called Parameter-Value-Matcher.
 * <p>For example: {@link MapperParameter}, {@link RequestBody}.</p>
 * <p>Use these annotations to automatically match and load the corresponding parameter values.</p>
 *
 * @author 谭波
 * @since 2024/3/22
 */
public interface IParametersAnnotationMatch {

    /**
     * Determine whether the argument tagged by Parameter-Value-Matcher is valid.
     *
     * @param parameter the parameter obj.
     * @throws ServletException Throw the {@link ServletException} when the parameter is not valid.
     */
    void isValidForParameter(Parameter parameter) throws ServletException;

    /**
     * The process of finding out the value of a parameter from parametersMap,
     * converting it accordingly, and storing it in parametersList.
     *
     * @param parametersMap  Parameters passed in by the {@link Servlet} caller.
     * @param parametersList The method arguments of {@link Servlet}.
     * @param parameter      the parameter obj.
     * @throws ServletException Throw the {@link ServletException} when fail to match parameter values.
     */
    void match(Map<String, Object> parametersMap, List<Object> parametersList, Parameter parameter) throws ServletException;

}
